//
//  MOOfficeTextSearchViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/10.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOOfficeTextSearchViewCell.h"

#define NAMELABELWIDTH    100
#define RIGHTIMAGEWIDTH   kWConversions(19)
#define VALUELABELWIDTH  SCREEN_WIDTH - kWConversions(15)*3 - RIGHTIMAGEWIDTH - NAMELABELWIDTH
#define INPUTTEXTFIELDWIDTH SCREEN_WIDTH - kWConversions(15)*3 - NAMELABELWIDTH

@interface MOOfficeTextSearchViewCell ()<UITextFieldDelegate>

@property(nonatomic,strong)UILabel *nameLabel;
//显示
@property(nonatomic,strong)UILabel *valueLabel;
//输入
@property(nonatomic,strong)UITextField *inputTextField;
//右箭头
@property(nonatomic,strong)UIButton *rightImageView;

@end

@implementation MOOfficeTextSearchViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    //NSString *ID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    NSString *ID = @"MOOfficeTextSearchViewCell";
    MOOfficeTextSearchViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MOOfficeTextSearchViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatView];
    }
    return cell;
}


-(void)creatView
{
    [self addSubview:self.nameLabel];
    [self addSubview:self.valueLabel];
    [self addSubview:self.inputTextField];
    [self addSubview:self.rightImageView];
}


-(void)setModel:(MOOfficeTextSearchModel *)model
{
    /*
     1.请输入 2.请选择
     */
    if ([model.typeStr integerValue]==1) {
        self.valueLabel.hidden = YES;
        self.rightImageView.hidden = YES;
        self.inputTextField.hidden = NO;
        
        self.inputTextField.text = model.valueStr;
    }else{
        self.valueLabel.hidden = NO;
        self.rightImageView.hidden = NO;
        self.inputTextField.hidden = YES;
        
        if (model.valueStr.length==0) {
            self.valueLabel.text = @"请选择";
        }else{
            self.valueLabel.text = model.valueStr;
        }
    }
    
    self.nameLabel.text = model.nameStr;
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSLog(@"%@",textField.text);
    if (self.inputEndBlock) {
        self.inputEndBlock(textField.text);
    }
}

#pragma mark -- 懒加载
-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWConversions(15), 0, NAMELABELWIDTH, kHConversions(54))];
        _nameLabel.textColor = KBlackColor_2A2A2A;
        _nameLabel.font = FONT_SIZE(15);
    }
    return _nameLabel;
}

-(UILabel *)valueLabel
{
    if (!_valueLabel) {
        _valueLabel = [[UILabel alloc]initWithFrame:CGRectMake(_nameLabel.right + kWConversions(15), 0, VALUELABELWIDTH, kHConversions(54))];
        _valueLabel.textColor = KGrayColor_919395;
        _valueLabel.font = FONT_SIZE(15);
        _valueLabel.textAlignment = NSTextAlignmentRight;
        _valueLabel.text = @"请选择";
    }
    return _valueLabel;
}

-(UITextField *)inputTextField
{
    if (!_inputTextField) {
        _inputTextField = [[UITextField alloc]initWithFrame:CGRectMake(_nameLabel.right + kWConversions(15), 0, INPUTTEXTFIELDWIDTH, kHConversions(54))];
        _inputTextField.delegate = self;
        _inputTextField.placeholder = @"请输入";
        _inputTextField.font = FONT_SIZE(15);
        _inputTextField.textColor = KGrayColor_919395;
        _inputTextField.textAlignment = NSTextAlignmentRight;
        [_inputTextField setValue:KGrayColor_919395 forKeyPath:@"_placeholderLabel.textColor"];
    }
    return _inputTextField;
}

-(UIButton *)rightImageView
{
    if (!_rightImageView) {
        _rightImageView = [[UIButton alloc]initWithFrame:CGRectMake(_valueLabel.right, 0, RIGHTIMAGEWIDTH, kHConversions(54))];
        [_rightImageView setImage:IMAGE(@"right_notice") forState:UIControlStateNormal];
        [_rightImageView setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentRight)];
        _rightImageView.userInteractionEnabled = NO;
    }
    return _rightImageView;
}


@end
